﻿@using Microsoft.Practices.Unity;
@using Vit.Web.Providers;
@using Vit.Web.Mvc.DataAnnotations;
@{
    string val = string.Empty;
    List<SelectListItem> dataSource = new List<SelectListItem>();
    dataSource.Add(new SelectListItem() { Text = "", Value = "" });
    DataSourceAttribute attr = ViewData.ModelMetadata.AdditionalValues[DataSourceAttribute.AttributeKey] as DataSourceAttribute;
    if (attr != null)
    {
        IDataSourceProvider dsProvider = Unity.Current.Resolve<IDataSourceProvider>(string.Format("DataSource:{0}", attr.DataSourceType.Name));

        if (dsProvider != null)
        {
            var items = dsProvider.GetSourceList(null);
            dataSource.AddRange(items);
            if(this.Model != null)
            {
                var item = dataSource.FirstOrDefault(o => o.Value == this.Model.ToString());
                if (item != null)
                { 
                    item.Selected = true;
                }
            }
        }
    }
}
@Html.DropDownList(string.Empty, dataSource)